﻿using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace SystemDiagramNew.Utils
{
	public static class ControlExternsion
	{
		public static void SetValue<T>(this System.Windows.Forms.Control ctrl, T value) where T : IFormattable
		{
			ctrl.Text = value.ToString();
		}

		public static T GetValue<T>(this System.Windows.Forms.Control ctrl, T defValue)
		{
			string value = ctrl.Text.Trim();
			if (string.IsNullOrEmpty(value))
			{
				return defValue;
			}
			return (T)((object)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(value));
		}
	}
}
